# -*- encoding: utf-8 -*-
"""
    Created by Rachel on 2025/02/19
"""

class Expression:

    def __init__(self, model, domain):
        self.model = model
        self.domain = domain

    def parse(self):
        result = []
        for field_name, field_value in self.domain.items():
            if isinstance(field_value, list):
                result.append(getattr(self.model, field_name).in_(field_value))
            elif isinstance(field_value, dict):
                if field_value.get("like", None):
                    result.append(getattr(self.model, field_name).like("%{}%".format(field_value.get("like", None))))
                elif field_value.get("not_equal", None):
                    result.append(getattr(self.model, field_name) != "{}".format(field_value.get("not_equal", None)))
                elif field_value.get("not_in", None):
                    result.append(getattr(self.model, field_name).not_in(field_value.get("not_in", None)))
                else:
                    min_value = field_value.get("min")
                    max_value = field_value.get("max")
                    result.append(getattr(self.model, field_name).between(min_value, max_value))
            else:
                result.append(getattr(self.model, field_name) == field_value)

        return result

if __name__ == "__main__":
    cond = ["|", ("id", "=", 12), ("id", "=", 13), ("account", "like", "三")]
